<?php
/**
 * 退款结果通知POS后台
 */

namespace App\Services\PosApi;


use App\Jobs\RefundConfirmJob;
use Illuminate\Support\Facades\Log;
use App\Services\Java\ApiService;

class RefundConfirm
{
    public function handle($refund)
    {

        $data = [
            'no'=>$refund['order_no'],
            'refundNo'=>$refund['refund_no'],
        ];
        Log::info('sync:java-退款'.var_export($data,1));
        try {
            $rs = (new ApiService())->requestJava('/pay/api/order/refund-success',$data,'post');
        } catch (JavaApiException $e) {
            if(!isset($refund['is_job'])){ //队列会再请求当前方法，防止队列里再发布队列
                $jobData = $refund;
                $jobData['is_job'] = true;
                RefundConfirmJob::dispatch($jobData);
            }
            Log::error("退款单{$refund['refund_no']}回调失败，错误消息：". $e->getMessage());
        }
        Log::info('sync:java-退款成功'.var_export($rs,1));
    }


}